package com.tiantian.filterandInterceptor.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 设置过滤器顺序
 */
@Configuration
public class FilterConfig {

    @Autowired
    private Filter01 filter01;
    @Autowired
    private Filter02 filter02;

    @Bean
    public FilterRegistrationBean registFilter01() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(filter01);
        registrationBean.setName("filter01");
        //数字越小先执行
        registrationBean.setOrder(1);
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean registFilter02() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(filter02);
        registrationBean.setName("filter02");
        //数字越小先执行
        registrationBean.setOrder(2);
        return registrationBean;
    }
}
